const {
	Service
} = require('uni-cloud-router')
const uniID = require('uni-id')
const dbHelper = require('db-helper')

module.exports = class VipCardService extends Service {

	async getVipCardList(cityCode) {
		let list = await dbHelper.getList("t3ds-vip-card", {
			onSell: true
		})
		for (var i = 0; i < list.length; i++) {
			let item = list[i]
			if (item.settlementWay === 'time' && item.time === 'oneYear') {
				let count = await dbHelper.getCount("t3ds-store", {
					joinFreePlan: true,
					enabled: true,
					'region.city.value': cityCode
				})
				item.serviceCount = count
			} else if (item.type == 'merchant') {
				let query = {
					joinFreePlan: true,
					enabled: true,
					'region.city.value': cityCode
				}
				if (item.serviceCategoryIds.length) {
					query.categoryId = this.db.command.in(item.serviceCategoryIds)
				}
				let count = await dbHelper.getCount("t3ds-store", query)
				item.serviceCount = count
			}
		}
		return list
	}
}
